/**
 * Created by huachuan on 2016/1/21.
 */
angular.module('calendarservices',[])
  //约局的Service
  .factory('Calendar', function($resource,$rootScope,ENV) {

    var APIUrl = ENV.api;
    //获取$resource
    var weekDaysJson,monthDayJson;
    var getCalendarDetailResource = $resource(APIUrl + 'calendar/getDayHaveMeeting.do');
    var getMonthActivityResource = $resource(APIUrl + 'calendar/getMonthActivity.do');

    return {
      getMonthActivity:function(date,memberId,cityId,cityName){
        getMonthActivityResource.save({
          MONTH_DATE:date,
          member_id:memberId,
          shop_city_id:cityId,
          city_name:cityName
        },function(response){
          monthDayJson = response;
          $rootScope.$broadcast('Calendar.getMonthActivityUpdated');
        });
      },
      getMonthActivityJson:function(){
          return monthDayJson;
      },
      //获取周日历，并获取当天是否有活动
        getCalendar:function(week,tip,memberId,cityId,cityName) {
          getCalendarDetailResource.save({
            week_days:week,
            member_id:memberId,
            city_id:cityId,
            city_name:cityName
          },function(response){
            weekDaysJson = response.week_days;
            if(tip=='indexActivity'){
              $rootScope.$broadcast('Calendar.getCalendarUpdated');
            }else if(tip=='dayActivity'){
              $rootScope.$broadcast('Calendar.getDayActivityCalendarUpdated');
            }
          });
        },
      getWeekDayJson:function(){
        return weekDaysJson;
      }
    }

  })
